<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="css/common.css"/>
    <link rel="stylesheet" href="css/main.css"/>
    <link rel="stylesheet" href="css/jquery-ui-timepicker-addon.css"/>
    <link rel="stylesheet" href="css/jquery-ui.css"/>
    <link href="css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="css/city-picker.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="css/jquery-impromptu.min.css" type="text/css"/>
    <link rel="stylesheet" href="css/combo.select.css" type="text/css"/>
    <title>关联出差审批单信息</title>
</head>
<body>
<div id="dataLoad" style="display:none; position: fixed; width: 100%; top: 20%; z-index: 1001;">
       <table width=100% height=100% border=0 align=center valign=middle>
        <tr height=50%><td align=center>&nbsp;</td></tr>
        <tr><td align=center><img src="images/loading.gif"/></td></tr>
        <tr><td align=center>提交中，请稍后......</td></tr>
        <tr height=50%><td align=center>&nbsp;</td></tr>
       </table>
     </div>
<div class="container">
    <div id="search_bar" class="mt10">
        <div class="box">
            <div class="box_border">
                <div class="box_top"><b class="pl15">同行人员</b></div>
                <div class="box_center pt10 pb10">
                    <table class="form_table" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>选择部门</td>
                            <td>
                    <span class="fl">
                      <div class="select_border">
                          <div class="select_containers ">
                              <select name="" class="select" id="depart-select" disabled>

                              </select>
                          </div>
                      </div> 
                    </span>
                            </td>
                            <td>选择人员</td>
                            <td>
                    <span class="fl">
                      <div class="select_border">
                          <div class="select_containers ">
                              <select name="" class="select" id="user-select" disabled>
                              </select>
                          </div>
                      </div>
                    </span>
                            </td>
                            <td id="add_people_button"><a class="ext_btn disabled" ><span class="add"></span>添加</a></td>
                        </tr>
                    </table>
                </div>
                <div id="table" class="mt10">
                    <div class="box span10 oh">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" id="people_table">
                            <tr>
                                <th style="width: 10%" class="td_center">#</th>
                                <th style="width: 10%" class="td_center">序号</th>
                                <th style="width: 35%" class="td_center">人员姓名</th>
                                <th style="width: 35%" class="td_center">人员部门</th>
                                <th style="width: 10%" class="td_center">操作</th>
                            </tr>
                        </table>
                    </div>
                </div>

            </div>
        </div>
    </div>



    <div id="forms" class="mt10">
        <div class="box">
            <div class="box_border">
                <div class="box_top"><b class="pl15">出差申请信息</b></div>
                <div class="box_center">
                    <table class="form_table pt15 pb15" width="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td class="td_right">出差申请类型：</td>
                            <td class="">
                                <div class="select_border">
                                    <div class="select_containers" >
                                        <select name="" class="select" width="200px" id="business_type" disabled>
                                        </select>
                                    </div>
                                </div>
                      <span class="pl10" style="display:none" id="case_wrap">大案要案号/名：
                         <div class="select_border">
                             <div class="select_containers ">
                                 <select name="" class="select" id="case_info" disabled>
                                 </select>
                             </div>
                         </div>
                     </span>
                            </td>

                        </tr>
                        <tr>
                            <td class="td_right">出差省/市/区：</td>
                            <td>
                                <div id="distpicker" >
                                    <div class="form-group" style="width:500px; float: left">
                                        <div style="position: relative;">
                                            <input id="city-picker3" class="form-control" readonly type="text" value="四川省/宜宾市/翠屏区" data-toggle="city-picker">
                                        </div>
                                    </div>
                                    <div class="form-group" style="margin-left: 50px">
                                        <button class="btn btn-warning" id="reset" type="button">重置</button>
                                        <button class="btn btn-danger" id="destroy" type="button">确定</button>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td class="td_right">具体县/乡：</td>
                            <td class="">
                                <input type="text" placeholder="无" name="name" class="input-text lh25" size="20" id="county" disabled>
                            </td>
                        </tr>
                        <tr>
                            <td class="td_right">出差时间：</td>
                            <td class="">
                                <input type="text" placeholder="点击选择开始时间" name="business_start_time" class="input-text lh25" id="business_start_time" size="20" disabled>至
                                <input type="text" placeholder="点击选择结束时间" name="business_end_time" class="input-text lh25" id="business_end_time" size="20" disabled>天数
                                <input type="text" class="input-text lh25" name="days" id="days" disabled size="5">
                            </td>
                        </tr>
                        <tr>
                            <td class="td_right">出差原因：</td>
                            <td class="">
                                <textarea name="" id="business_reason" cols="30" rows="10" class="textarea" disabled></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td class="td_right">自驾车：</td>
                            <td class="">
                                <input type="radio" name="driveSelf" value="1" disabled> 是
                                <input type="radio" name="driveSelf" value="0" checked disabled> 否
                            </td>
                        </tr>
                        <tr>
                            <td class="td_right">相关附件：</td>
                            <td class="" id="upload_area">
                                <form id="upload_file_area" action="Upload" method="post" enctype="multipart/form-data">
                                    <input id="upload" type="file" style="display: none" multiple name="files[]" class="input-text lh30" size="10">
                                    <!--     <input id="upload2" type="file" style="display: none" name="file" class="input-text lh30" size="10">
                                         <input id="upload3" type="file" style="display: none" name="file" class="input-text lh30" size="10">-->
                                </form>
                                <a class="ext_btn disabled" id="uploadButton"><span class="upload"></span>上传</a>
                                <input id="filearea" type="text" class="input-text lh25" disabled size="50" placeholder="未上传任何附件">
                                <a class="ext_btn" id="clearFile" style="display: none;"><span class="del"></span>清空</a>
                                <a class="ext_btn" id="downloadButton" style="display:none"><span class="download"></span>下载</a>
                            </td>
                        </tr>
                        <tr>
                            <td class="td_right">是否借车：</td>
                            <td class="">
                                <input type="radio" name="isLoanCar" value="1" disabled> 是
                                <input type="radio" name="isLoanCar" value="0" checked disabled> 否
                                <a class="ext_btn" id="loanCar" style="display:none"><span class="loanCar"></span>借车申请</a>
                            </td>
                        </tr>
                        <tr>
                            <td class="td_right">是否借款：</td>
                            <td class="">
                                <input type="radio" name="isLoanMoney" value="1" disabled> 是
                                <input type="radio" name="isLoanMoney" value="0" checked disabled> 否
                                <a class="ext_btn" id="loanMoney" style="display:none"><span class="loanMoney"></span>借款申请</a>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="box_bottom pb5 pt5 pr10 modify_area" style="border:1px solid #dadada;">
        <div class="search_bar_btn" style="text-align:right;">
            <input type="button" id="modify_btn" name="button" class="btn1 btn82 btn_add disabled" value="修改" disabled>
            <input type="button" id="confirm_btn" name="button" class="btn1 btn82 btn_save2 disabled" value="确定" disabled>
            <input type="button" id="reset_btn" name="button" class="btn1 btn82 btn_res disabled" value="重置" disabled>
        </div>
    </div>
    <div class="box_bottom pb5 pt5 pr10 approve_area" style="border:1px solid #dadada;">
        <div class="search_bar_btn" style="text-align:right;">
            <input type="button" id="approve_btn" name="button" class="btn1 btn82 btn_config" value="审批">
        </div>
    </div>
    <div class="main_center span10 pt10" id="opinion_area">
        <div class="box_top">
            <b class="pl15">出差审批信息：</b>
            <select name="" class="select" style="border: 1px solid #003eff;background-color: #ffffff" id="approve_info">

            </select>
        </div>
        <div class="span33 fl pt10">
            <div class="box pr5">
                <div class="box_border" style="height: 230px">
                    <div class="box_top" id="section_top">
                        <b>部门审批意见</b>
                        <input class="ext_btn ext_btn_submit app_detail" type="submit" value="详情">
                    </div>
                    <div class="box_center opinion" id="section_opinion"><h1>待审批</h1></div>
                    <div class="box_center sign"><h3>签批人：<img id="section_sign"  width="100px" height="50px"></h3></div>
                </div>
            </div>
        </div>
        <div class="span33 fl pt10">
            <div class="box pl5 pr5">
                <div class="box_border" style="height: 230px">
                    <div class="box_top" id="section_leader_top">
                        <b>分管领导意见</b>
                        <input class="ext_btn ext_btn_submit app_detail" type="submit" value="详情">
                    </div>
                    <div class="box_center opinion" id="section_leader_opinion"><h1>待审批</h1></div>
                    <div class="box_center sign"><h3>签批人：<img id="section_leader_sign"  width="100px" height="50px"></h3></div>
                </div>
            </div>
        </div>
        <div class="span33 fl pt10">
            <div class="box pl5">
                <div class="box_border" style="height: 230px">
                    <div class="box_top" id="leader_top">
                        <b>局领导意见</b>
                        <input class="ext_btn ext_btn_submit app_detail" type="submit" value="详情">
                    </div>
                    <div class="box_center opinion" id="leader_opinion"><h1>待审批</h1></div>
                    <div class="box_center sign"><h3>签批人：<img id="leader_sign"  width="100px" height="50px"></h3></div>
                </div>
            </div>
        </div>
        <div class="clear"></div>
    </div>
        <div id="app_type_dialog" class="mt10" style="display:none" title="选择审批类型">
            <div class="box">
                <div class="box_center">
                    <table class="form_table pb15" id="approval_type_table" width="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td class="td_left">差旅单审批
                                <span class="pl5">
                                    <input type="button" id="app1_btn" name="button" class="btn1 btn82 btn_config" value="审批">
                                </span>
                                <span class="ui-state-error-text"><i class='ui-icon ui-icon-circle-close'></i>未审批</span>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div id="app_dialog" class="mt10" style="display:none" title="审批窗口">
        <div class="box">
            <div class="box_center">
                <table class="form_table pb15" width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td class="td_left">审批意见：
                    <span class="">
                        <div class="select_border">
                            <div class="select_containers ">
                                <select id="app_opinion" class="select">
                                    <option value="1">同意</option>
                                    <option value="0">驳回</option>
                                </select>
                            </div>
                        </div>
                    </span>
                        </td>
                    </tr>
                    <tr>
                        <td class="td_left">详细意见：</td>
                    </tr>
                    <tr>
                        <td class="">
                            <textarea name="" id="app_opinion_detail" cols="20" rows="30" placeholder="请填写具体审批意见" class="textarea">同意</textarea>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <div id="download_dialog" class="mt10" style="display:none" title="下载文件">
        <div class="box">
            <div class="box_center">
                <table class="form_table pb15" width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td class="td_left">选择文件：
                    <span class="">
                        <div class="select_border">
                            <div class="select_containers ">
                                <select id="file_area" class="select">
                                </select>
                            </div>
                        </div>
                    </span>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>
<div id="loanCar_dialog" class="mt10" style="display:none" title="借车申请">
    <div class="box">
        <div class="box_center">
            <table class="form_table pb15" width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td class="td_left">所属部门：</td>
                    <td class="">
                        <input type="text" placeholder="无" class="input-text lh25" size="20" id="loanCar_depart" disabled>
                    </td>
                </tr>
                <tr>
                    <td class="td_left">借车人员：</td>
                    <td class="">
                        <input type="text" placeholder="无" class="input-text lh25" size="20" id="loanCar_user" disabled>
                    </td>
                </tr>
                <tr>
                    <td class="td_left">借车事由：</td>
                    <td class="">
                        <textarea name="" id="loanCar_reason" cols="30" rows="10" class="textarea" disabled></textarea>
                    </td>
                </tr>
                <tr>
                    <td class="td_left">车牌号：</td>
                    <td class="" id="car_area">
                        <input type="text" placeholder="无" class="input-text lh25" id="loanCar_num" size="20" disabled>
                    </td>

                </tr>
                <tr>
                    <td class="td_left">专职驾驶员：</td>
                    <td class="">
                        <input type="radio" name="proDriver" value="0" checked disabled> 否
                        <input type="radio" name="proDriver" value="1" disabled> 是
                            <span class="pl10 driver_wrap" style="display:none" >驾驶员信息：
                                <div class="select_border">
                                    <div class="select_containers" >
                                        <select name="" class="select" width="200px" id="loanCar_driver" disabled>
                                        </select>
                                    </div>
                                </div>
                                <a class="ext_btn disabled" id="add_driver_btn"><span class="add"></span>添加</a>
                                <a class="ext_btn disabled" id="clear_driver_btn"><span class="del"></span>清空</a>
                            </span>
                    </td>
                </tr>
                <tr class="driver_wrap" style="display:none">
                    <td></td>
                    <td>
                        <textarea placeholder="驾驶员信息" name="" id="loanCar_driver_info" cols="30" rows="10" class="textarea" disabled></textarea>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<div id="loanMoney_dialog" class="mt10" style="display:none" title="借款申请">
    <div class="box">
        <div class="box_center">
            <table class="form_table pb15" width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td class="td_left">所属部门：</td>
                    <td class="">
                        <input type="text" placeholder="无" class="input-text lh25" size="20" id="loanMoney_depart" disabled>
                    </td>
                </tr>
                <tr>
                    <td class="td_left">借款人：</td>
                    <td class="">
                        <input type="text" placeholder="无" class="input-text lh25" size="20" id="loanMoney_user" disabled>
                    </td>
                </tr>
                <tr>
                    <td class="td_left">借款事由：</td>
                    <td class="">
                        <textarea name="" id="loanMoney_reason" cols="30" rows="10" class="textarea" disabled></textarea>
                    </td>
                </tr>
                <tr>
                    <td class="td_left">借款金额：</td>
                    <td class="">
                        <input type="number" placeholder="0" class="input-text lh25" size="20" id="loanMoney_amount" disabled>
                        <span></span>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/colResizable-1.6.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="js/datapicker_cn.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script src="js/city-picker.data.js"></script>
<script src="js/city-picker.js"></script>
<script src="js/main.js"></script>
<script src="js/config.js" type="text/javascript"></script>
<script src="js/business_approve.js" type="text/javascript"></script>
<script src="js/jquery-impromptu.min.js" type="text/javascript"></script>
<script src="js/download.min.js" type="text/javascript"></script>
<script src="js/jquery.combo.select.js" type="text/javascript"></script>
<script>
    var loanCarData = {};
    var loanMoneyData = {};
    var isSetCarData = false;
    var isSetMoneyData = false;
    var isModifyMode = false;

    var needApprove = 0;
    var approveState = {'needBusi': false, 'approveBusi': false, 'needCar':false, 'approveCar':false, 'needMoney':false, 'approveMoney':false};
    var approveOpinion = {'approveCar':0, 'approveMoney':0};

    //判断到底是什么在审批, 0 出差， 1借车，2借款
    var curAppType = 0;

    //存放当前数据全局变量
    var curItem = {};

    //辅助函数，处理借车信息显示
    function setLoanCarArea(){
        //两种情况，如果一开始有借车数据，或者已经填写过借车数据
        if(isSetCarData){
            $('#loanCar_depart').val(loanCarData.section_name);
            $('#loanCar_user').val(loanCarData.user_name);
            $('#loanCar_reason').val(loanCarData.reason);
            $('#loanCar_num').val(loanCarData.carNum);
            if(loanCarData.driverID != ''){
                $(":radio[name='proDriver'][value='1']").prop('checked', 'checked');
                $('.driver_wrap').show();
                $('#loanCar_driver_info').val(loanCarData.driverName);
            }
            else{
                $(":radio[name='proDriver'][value='0']").prop('checked', 'checked');
            }
        }
        else{ //如果一开始没有借车数据，或者取消过借车数据
            $('#loanCar_depart').val(selectUser[0].departText);
            $('#loanCar_user').val(selectUser[0].userText);

            loanCarData.section_name = selectUser[0].departText;
            loanCarData.user_id = selectUser[0].userVal;
            loanCarData.depart_id = selectUser[0].departVal;
            loanCarData.user_name = selectUser[0].userText;
        }


        $("input[name='proDriver']").click(function(){
            if($(this).val() == 1){
                $('.driver_wrap').show();
            }
            else{
                $('.driver_wrap').hide();
            }
        })


    }
    //辅助函数，初始化借款区域信息
    function setLoanMoneyArea(){
        //如果已经设置过借款数据
        if(isSetMoneyData){
            $('#loanMoney_depart').val(loanMoneyData.section_name);
            $('#loanMoney_user').val(loanMoneyData.user_name);
            $('#loanMoney_reason').val(loanMoneyData.reason);
            $('#loanMoney_amount').val(loanMoneyData.money);
        }//如果一开始没有借款数据，或取消过借款数据
        else{
            $('#loanMoney_depart').val(selectUser[0].departText);
            $('#loanMoney_user').val(selectUser[0].userText);
            loanMoneyData.section_name = selectUser[0].departText;
            loanMoneyData.user_id = selectUser[0].userVal;
            loanMoneyData.depart_id = selectUser[0].departVal
            loanMoneyData.user_name = selectUser[0].userText;
        }
    }

    //辅助函数,初始化签名和意见
    function setOpinionArea(){
        var appVal = $('#approve_info').val();
    //    alert(appVal);
        ShowApproveDetail();
        switch(appVal){
            case 'ap':
                setApproveOpinion(curItem, 1);
                break;
            case 'loanCar':
                setApproveOpinion(curItem.loan_car, 3);
                break;
            case 'loanMoney':
                setApproveOpinion(curItem.loan_money, 2);
                break;
        }
    }




    //辅助函数，处理有借车审批的情况
    function setCarApprove(){
        $('#loanCar').show();
        isSetCarData = true;
        loanCarData = curItem.loan_car;
        $('#approve_info').append("<option value='loanCar'>借车审批信息</option>");
        //在弹出选择类型中添加借车审批按钮
        $('#approval_type_table').append("<tr>" +
                "<td class='td_left'>借车单审批&nbsp;" +
                "<span class='pl5'>" +
                "<input type='button' id='app_car_btn' name='button' class='btn1 btn82 btn_config' value='审批'>&nbsp;"+
                "</span><span class='ui-state-error-text'><i class='ui-icon ui-icon-circle-close'></i>未审批</span>" +
                "</td></tr>");
        needApprove++;
        //approveState.needCar = true;
        processCarApprove();
    }
    //辅助函数，处理借车审批
    function processCarApprove(){
        $('#app_car_btn').click(function(){
            curAppType = 2;
            $('#app_opinion_detail').val('同意借车');
            $('#app_dialog').dialog({
                resizable: false,
                height: "auto",
                width: 430,
                modal: true,
                title: '借车单审批',
                buttons: {
                    '确定' :function(){
                        //确定已经审批了借车单
                        needApprove--;
                       // approveState.approveCar = true;
                        //获取数据
                        approveOpinion.car_opinion = {
                            'app_opinion': $('#app_opinion').val(),
                            'app_opinion_detail' : $('#app_opinion_detail').val()
                        };
                        approveOpinion.approveCar = 1;
                        changeState($('#app_car_btn'));
                        $(this).dialog("close");
                    },
                    '取消': function(){
                        $(this).dialog("close");
                    }
                }
            });
        })
    }
    //辅助函数，处理有借款审批的情况
    function setMoneyApprove(){
        $('#loanMoney').show();
        isSetMoneyData = true;
        loanMoneyData = curItem.loan_money;
        $('#approve_info').append("<option value='loanMoney'>借款审批信息</option>");
        //在弹出选择类型中添加借款审批按钮
        $('#approval_type_table').append("<tr>" +
                "<td class='td_left'>借款单审批&nbsp;" +
                "<span class='pl5'>" +
                "<input type='button' id='app_fee_btn' name='button' class='btn1 btn82 btn_config' value='审批'>&nbsp;"+
                "</span><span class='ui-state-error-text'><i class='ui-icon ui-icon-circle-close'></i>未审批</span>" +
                "</td></tr>");
        //approveState.needMoney = true;
        needApprove++;
        processMoneyApprove();
    }
    //辅助函数，处理借款审批
    function processMoneyApprove(){
        $('#app_fee_btn').click(function(){
            curAppType = 1;
            $('#app_opinion_detail').val('同意借款');
            $('#app_dialog').dialog({
                resizable: false,
                height: "auto",
                width: 430,
                modal: true,
                title: '借款单审批',
                buttons: {
                    '确定' :function(){
                        //确定已经审批了借款单
                        needApprove--;
                        //approveState.approveMoney = true;
                        //获取数据
                        approveOpinion.money_opinion = {
                            'app_opinion': $('#app_opinion').val(),
                            'app_opinion_detail' : $('#app_opinion_detail').val()
                        };
                        approveOpinion.approveMoney = 1;
                        changeState($('#app_fee_btn'));
                        $(this).dialog("close");
                    },
                    '取消': function(){
                        $(this).dialog("close");
                    }
                }
            });
        })
    }

    //辅助函数，处理出差单审批
    function processBussinessApprove(){
        $('#app1_btn').click(function(){
            curAppType = 0;
            $('#app_opinion_detail').val('同意出差');
            $('#app_dialog').dialog({
                resizable: false,
                height: "auto",
                width: 430,
                modal: true,
                title: '差旅单审批',
                buttons: {
                    '确定' :function(){
                        //确定已经审批了借款单
                        needApprove--;
                        //approveState.approveBusi = true;
                        //获取数据
                        approveOpinion.busi_opinion = {
                            'app_opinion': $('#app_opinion').val(),
                            'app_opinion_detail' : $('#app_opinion_detail').val()
                        };
                        approveOpinion.approveBusi = 1;

                        changeState($('#app1_btn'));


                        $(this).dialog("close");
                    },
                    '取消': function(){
                        $(this).dialog("close");
                    }
                }
            });
        })
    }



    //辅助函数，初始化所有数据
    function setItemData(){

        if(curItem.state == 2){
            $('#downloadButton').hide();
            $('#modify_btn').removeClass('disabled').attr('disabled', false);
            $('#reset_btn').removeClass('disabled').attr('disabled', false);
        }

        //获取同行人
        var comp = curItem.companion;

        //添加同行人
        for(var i = 0; i < comp.length; i++){
            if(i == 0){
                $('#people_table').append("<tr class='tr user_tr'> " +
                        "<td class='td_center'><input type='checkbox'></td> " +
                        "<td class='td_center'>" + (i + 1) +  "</td> " +
                        "<td class='td_center'>" + comp[i]['comp_user_name'] + "</td>" +
                        "<td class='td_center'>" + comp[i]['comp_depart_name'] + "</td>" +
                        "<td class='td_center'></td>" +
                        "</tr>");
            }
            else{
                $('#people_table').append("<tr class='tr user_tr'> " +
                        "<td class='td_center'><input type='checkbox'></td> " +
                        "<td class='td_center'>" + (i + 1) +  "</td> " +
                        "<td class='td_center'>" + comp[i]['comp_user_name'] + "</td>" +
                        "<td class='td_center'>" + comp[i]['comp_depart_name'] + "</td>" +
                        "<td class='td_center'><a style='display:none' href='' class='ext_btn del_btn'><span class='del'></span>删除</a></td>" +
                        "</tr>");
            }
            selectUser.push({'departText': comp[i]['comp_depart_name'], 'departVal': comp[i]['comp_depart_id'],
                'userText': comp[i]['comp_user_name'], 'userVal': comp[i]['comp_user_id']});
        }

        //如果是大案要案
        if(curItem.type == 2){
            $('#case_info').val(curItem['case_ID']);
            $('#business_type').val(curItem.type);
            $('#business_type').trigger('change');
        }
        //处理地址，分开
        var dest = curItem.destination.split('/');
        var t1 = dest[0]+ '/' + dest[1] + '/' + dest[2];
        var t2 = dest[3];

        $('#city-picker3').val(t1);
        $('#destroy').click();
        $('#county').val(t2);

        $('#business_start_time').val(curItem.start_time);
        $('#business_end_time').val(curItem.end_time);
        $('#days').val(curItem.days);
        $('#business_reason').val(curItem.reason);
        $('#reset').attr('disabled', true);
        $('#destroy').attr('disabled', true);
        var self_drive = parseInt(curItem.self_drive);
        if(self_drive){
            $("input[name='driveSelf']").get(0).checked = true;
        }
        else{
            $("input[name='driveSelf']").get(1).checked = true;
        }

        $('#filearea').val(curItem.files);



        $("input[name='isLoanMoney']").each(function(){
            if($(this).val() == curItem.is_loan_money){
                $(this).attr('checked', true);
            }
        });

        $("input[name='isLoanCar']").each(function(){
            if($(this).val() == curItem.is_loan_car){
                $(this).attr('checked', true);
            }
        });
       $('#approve_info').append("<option value='ap'>出差审批信息</option>");
        //如果有借款申请，显示借款申请按钮,处理借款申请相关信息
        if(curItem.is_loan_money){
            setMoneyApprove(curItem);
        }
        //如果有借车申请，显示借车申请按钮,处理借车申请相关信息
        if(curItem.is_loan_car){
            setCarApprove(curItem);
        }
        setOpinionArea(curItem);

    }


    //辅助函数，显示详细审批意见
    function ShowApproveDetail(){
        var app_info_type = $('#approve_info').val();
        var msg = {'section':'', 'section_leader':'', 'leader':''};
        switch(app_info_type){
            case 'ap':
                msg.section = curItem.section_approve_opinion;
                msg.section_leader = curItem.section_leader_opinion;
                msg.leader = curItem.leader_opinion;
                break;
            case 'loanCar':
                msg.section = curItem.loan_car.section_approve_opinion;
                msg.section_leader = curItem.loan_car.section_leader_opinion;
                msg.leader = curItem.loan_car.leader_opinion;
                break;
            case 'loanMoney':
                msg.section = curItem.loan_money.section_approve_opinion;
                msg.section_leader = curItem.loan_money.section_leader_opinion;
                msg.leader = curItem.loan_money.leader_opinion;
                break;
        }
        $('.app_detail').each(function(){
            $(this).unbind('click');
        });
        var app_details = $('.app_detail');
        $(app_details[0]).click(function(){
            $.prompt( "<p>" + (msg.section == '' ? '未审批' : msg.section) + "</p>",{
                title: '审批详细信息',
                buttons: {'确定': true}
            });
        })
        $(app_details[1]).click(function(){
            $.prompt( "<p>" + (msg.section_leader == '' ? '未审批' : msg.section_leader) + "</p>",{
                title: '审批详细信息',
                buttons: {'确定': true}
            });
        })
        $(app_details[2]).click(function(){
            $.prompt( "<p>" + (msg.leader == '' ? '未审批' : msg.leader) + "</p>",{
                title: '审批详细信息',
                buttons: {'确定': true}
            });
        })

    }


    function onEdit(){
        $('#modify_btn').click(function(e){
            isModifyMode = true;
            //禁用本身
            $(this).addClass('disabled');
            $(this).attr('disabled', 'true');
            //启用确定按钮
            $('#confirm_btn').removeClass('disabled');
            $('#confirm_btn').attr('disabled', false);
            //启用部门选择
            $('#depart-select').attr('disabled', false);
            //启用用户选择
            $('#user-select').attr('disabled', false);
            //启用添加按钮
            $('#add_people_button a').removeClass('disabled');
            //启用目前所有已经添加条目的删除按钮
            $('.del_btn').each(function(index){
                $(this).on('click', function(e){
                    deleteUserItem(this);
                    //防止默认按钮的操作
                    e.preventDefault();
                })
            });
            //启用大案要案选择
            $('#case_info').attr('disabled', false);

            //处理添加人员的按钮
            AddUser();
            //显示删除按钮
            $('.del_btn').show();
            //启用出差类别选择
            $('#business_type').attr('disabled', false);
            //启用省市区的重置按钮和确定按钮
            $('#reset').attr('disabled', false);
            $('#destroy').attr('disabled', false);
            //模拟重置操作
            $('#reset').click();
            //启用县乡输入
            $('#county').attr('disabled', false);
            //启用开始日期和结束日期的选择
            $('#business_start_time').attr('disabled', false);
            $('#business_end_time').attr('disabled', false);
            //处理日期天数的计算
            calcDays();
            //启用上传按钮
            $('#uploadButton').removeClass('disabled');
            //启用出差理由输入
            $('#business_reason').attr('disabled', false);
            //启用自驾车选择
            $("input[name='driveSelf']").attr('disabled', false);

            //清空文件
            $('#filearea').val('');

            //启用借车选择
            $("input[name='isLoanCar']").attr('disabled', false);
            $("input[name='isLoanMoney']").attr('disabled', false);

            //启用借车相关输入框
            $('#loanCar_reason').attr('disabled', false);
            $('#loanCar_num').attr('disabled', false);
            $("input[name='proDriver']").attr('disabled', false);
            $("#loanCar_driver").attr('disabled', false);
            $("#add_driver_btn").removeClass('disabled');
            $('#clear_driver_btn').removeClass('disabled');

            addDriver();
            clearDriver();

            //启用借款相关输入框
            $('#loanMoney_reason').attr('disabled', false);
            $('#loanMoney_amount').attr('disabled', false);

            setDataPicker();
            processTime();
        })
    }
    //辅助函数，下载文件处理
    function downloadFile(){
        $('#downloadButton').click(function(){

            if(curItem.files.length != 0){
                var files = curItem.files.split(';');
                for(var i = 0; i < files.length - 1; i++){
                    $('#file_area').append("<option value=" + (i+1) + ">" + files[i] + "</option>");
                }
                $('#download_dialog').dialog({
                    resizable: false,
                    height: "auto",
                    width: 430,
                    modal: true,
                    buttons:{
                        '确定': function(){
                            var id = $('#file_area').val() - 1;
                            var fileUrl = url + 'uploads/files/approval/' + curItem.approval_ID + "/" + files[id];
                            window.open(fileUrl);
                        },
                        '关闭': function(){
                            $(this).dialog('close');
                        }
                    }
                })
            }

        })
    }

    //辅助函数，设置审批状态
    function setApproveState(){
        //如果是审批状态
        var state = window.localStorage.getItem('approve_state');
        $('#downloadButton').show();
        if(state == 1){
            //设置审批状态
            needApprove++;
            //approveState.needBusi = true;
            $('.modify_area').hide();
            $('.approve_area').show();
            //隐藏上传和清空按钮,显示下载按钮
            $('#uploadButton, #clearFile').hide();

            downloadFile();
            $('#app_opinion').change(function(){
                if($(this).val() == 1){
                    if(curAppType == 0)
                        $('#app_opinion_detail').val('同意出差');
                    if(curAppType == 1)
                        $('#app_opinion_detail').val('同意借款');
                    if(curAppType == 2)
                        $('#app_opinion_detail').val('同意借车');
                }
                else{
                    $('#app_opinion_detail').val('');
                }
            });
            processBussinessApprove();
            $('#approve_btn').click(function(){
                $('#app_type_dialog').dialog({
                    resizable: false,
                    height: "auto",
                    width: 430,
                    modal: true,
                    title: '审批选择',
                    buttons: {
                        '确定': function(){
                            if(needApprove > 0){
                                $.prompt( "<h3>还有未审批的单据</h3>",{
                                    title: '操作提醒',
                                    buttons: {'确定': true}
                                });
                            }
                            else{
                                ApproveCurItem();
                                $(this).dialog("close");
                            }

                        },
                        '取消': function(){
                            $(this).dialog("close");
                        }
                    }
                })
            })
        }
        else{
            $('.modify_area').show();
            $('.approve_area').hide();
        }
    }
    //辅助函数，审批出差信息
    function ApproveCurItem(){
        $('#dataLoad').show();
        var userInfo = JSON.parse(window.localStorage.getItem('user_info'));
        var identity = window.localStorage.getItem('approve_type');
        approveOpinion.userID = userInfo.user_id;
        approveOpinion.approve_state = identity;
        approveOpinion.approve_id = curItem.approval_ID;
        $.post(url+'BusinessApprove/ApproveBusiness.php', approveOpinion, function(data){
                    $('#dataLoad').hide();
                    var t = JSON.parse(data);
                    if(t.state == 1){
                        $.prompt( "<h3>操作成功</h3>",{
                            title: '消息提醒',
                            buttons: {'确定': true},
                            submit: function(e, v, m, f){
                                if(v)
                                    jumpPage('section_approve.html');
                            }
                        });
                    }
                    else{
                        $.prompt( "<h3>网络或数据库错误，请稍后再试</h3>",{
                            title: '消息提醒',
                            buttons: {'确定': true}
                        });
                    }
        })

    }



    //辅助函数，处理状态的改变
    function changeState(elem){
        $(elem).parent().next().removeClass('ui-state-error-text').html("<i class='ui-icon ui-icon-circle-check'></i>已审批")
    }
    $(function(){
        //获取当前数据
        curItem = JSON.parse(window.localStorage.getItem('cur_travel_info'));
        getDriver();
        setApproveState();
        getBusinessType();
        getSection();
        getSectionMember();
        //处理大案要案选择
        getCaseInfo();

        //处理借款和借车按钮
        processLoanCarBtn();
        processLoanMoneyBtn();


        //编辑按钮按下后的操作
        onEdit();
        processUploadFile();
        setTimeout(function(){
            setItemData();
        }, 20);

        processBusinessTypeChange();

        $('#approve_info').change(function(){
            setOpinionArea();
        });


        //处理确定按钮
        $('#confirm_btn').click(function(){
            var postData = createPostData();
            console.log(postData);
            if(!postData)
                return;
            postData.isLoanMoney = isSetMoneyData;
            postData.loanMoneyData = loanMoneyData;
            postData.isLoanCar = isSetCarData;
            postData.loanCarData = loanCarData;

            uploadData(postData);
        });

        //处理重置按钮
        $('#reset_btn').click(function(){
            clearData();
        });


        //处理借车申请查看

        $('#loanCar').click(function(){
            setLoanCarArea();
            $('#loanCar_dialog').dialog({
                resizable: false,
                height: "auto",
                width: 600,
                modal: true,
                buttons: {
                    '确定' :function(){
                        if(isModifyMode)
                        {
                            var driverData = processLoanCarData();
                            if(!driverData){
                                $.prompt("<h3>未填写借车理由，请补完</h3>", {
                                    title: '错误提醒',
                                    buttons: {'确定': true}
                                })
                            }
                            else{
                                isSetCarData = true;
                                $(this).dialog("close");
                            }
                        }
                        else{
                            $(this).dialog("close");
                        }

                    },
                    '取消': function(){
                        $(this).dialog("close");
                    }
                }
            });
        })
        $('#loanMoney').click(function(){
            setLoanMoneyArea();
            $('#loanMoney_dialog').dialog({
                resizable: false,
                height: "auto",
                width: 600,
                modal: true,
                buttons: {
                    '确定' :function(){
                        if(isModifyMode) {
                            var t = processFeeInput($('#loanMoney_amount'));
                            var r = $('#loanMoney_reason').val();
                            if (!t || r == '') {
                                $.prompt("<h3>金额输入错误或未填写借款原因，请改正</h3>", {
                                    title: '错误提醒',
                                    buttons: {'确定': true}
                                })
                            } else {
                                processLoanMoneyData();
                                isSetMoneyData = true;
                                $(this).dialog("close");
                            }
                        }
                        else{
                            $(this).dialog("close");
                        }
                    },
                    '取消': function(){
                        $(this).dialog("close");
                    }
                }
            });
        })


    })

</script>